<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>随机点名案例</title>
</head>
<body>
  <button onclick="a()">开始</button>
  <button onclick="b()">结束</button>
  <p></p>
  <!-- 点击开始按钮，开始随机点名，点击结束，显示名字 -->
  <script>
    var arr = ['张三', '李四', '王五', '赵六']
    var p = document.querySelector('p'), time;
    function a() {
      time = setInterval(fn, 50)
      function fn() {
        p.innerHTML = arr[Math.floor(Math.random() * arr.length)]
      }
    }
    function b() {
      clearInterval(time)
    }
  </script>
</body>
</html>